package com.vae.service.impl;


import com.vae.service.CheckCodeService;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * 数字字母生成器
 */
@Component("NumberLetterCheckCodeGenerator")
public class NumberLetterCheckCodeGenerator implements CheckCodeService.CheckCodeGenerator {

    @Override
    public String generate(int length) {
        String str="ABCDEFGHJKMNPQRSTWXY23456789";//验证码的可取值
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(28);//这个28要跟第16行的可取值数量相等
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}